//
//  RW_HomeView.m
//  SleepApp
//
//  Created by MAC on 2021/3/19.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_HomeItemView.h"
#import "WLNavigationScrollModel.h"
#import "RW_SingleModel.h"
#import "RW_HomeItemViewModel.h"
#import "RW_MusicItemCollectionViewCell.h"
#import "RW_PlayerViewController.h"
#import "RW_PlaySingleCollectionReusableView.h"
#import "RW_PushPlayersTools.h"

@interface RW_HomeItemView ()
@property (nonatomic,strong) RW_HomeItemViewModel *wlclass_view_model;
@property (nonatomic,strong) RW_PlaySingleCollectionReusableView *wlclass_header_view;
@property (nonatomic,strong) WLCollectionView *wlclass_collection;
@end
@implementation RW_HomeItemView
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = HexColor(@"f6f6f6");
        [self addSubview:self.wlclass_header_view];
        [self addSubview:self.wlclass_collection];
        [self.wlclass_header_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.mas_equalTo(self);
            make.height.mas_offset(45);
        }];
        [self.wlclass_collection mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.mas_equalTo(self);
            make.bottom.mas_equalTo(self).mas_offset(-45);
        }];
    }
    return self;
}
/** 数据加载 */
-(void)beginRefreshData:(WLNavigationScrollModel *)model{
    if ([model.data isKindOfClass:RW_SingleModel.class]){
        [self initData:model.data];
    }
}
-(void)navigationContentCellShow:(WLNavigationScrollModel *)sender{
    WLLog;
}
#pragma mark -- 数据加载
-(void)initData:(RW_SingleModel *)data{
    self.wlclass_view_model.singleModel = data;
    
    RW_PlaySingleCollectionReusableViewModel *headerModel = [[RW_PlaySingleCollectionReusableViewModel alloc]init];
    headerModel.singleModel = data;
    self.wlclass_header_view.model = headerModel;
    
    [self.wlclass_view_model getCellSuccess:^(NSArray<WLBaseCollectionViewLayerSection *> *response) {
        [self.wlclass_collection setAllSection:response];
    } fail:^(NSError *error) {
        
    }];
}
#pragma mark -- WLCollectionView 代理
- (void)wl_collectionView:(UICollectionView *)collectionView
               layerModel:(WLBaseCollectionViewLayerModel *)layerModel
             layerRowData:(id)rowData
             didIndexPath:(NSIndexPath *)indexPath{
    if ([rowData isKindOfClass:RW_MusicItemCollectionViewCellModel.class]){
        RW_MusicItemCollectionViewCellModel *model = rowData;
        [RW_PushPlayersTools pushSongId:model.songModel.xid fromVc:[self viewController_wl]];
    }
}
#pragma mark -- 懒加载
-(RW_HomeItemViewModel *)wlclass_view_model{
    if (!_wlclass_view_model){
        _wlclass_view_model = [[RW_HomeItemViewModel alloc]init];
    }
    return _wlclass_view_model;
}
-(WLCollectionView *)wlclass_collection{
    if(!_wlclass_collection){
        _wlclass_collection = [WLCollectionView initWithVerticalDelegate:self];
    }
    return _wlclass_collection;
}
-(RW_PlaySingleCollectionReusableView *)wlclass_header_view{
    if (!_wlclass_header_view){
        _wlclass_header_view = [[RW_PlaySingleCollectionReusableView alloc]init];
    }
    return _wlclass_header_view;
}
@end
